package dicebot.tools.dice;

public class Multiple extends DiceExpression {
    
    public DiceExpression var1, var2;
    
    @Override
    public DiceExpression simplify() throws Exception {
        if (var1 instanceof Number && var2 instanceof Number) {
            return new Number(((Number) var1).value * ((Number) var2).value);
        } else {
            var1 = var1.simplify();
            var2 = var2.simplify();
            return this;
        }
    }

    public Multiple (DiceExpression var1, DiceExpression var2) {
        this.var1 = var1;
        this.var2 = var2;
    }

    @Override
    public String toString() {
        String s1 = var1.toString();
        if (var1 instanceof Add || var1 instanceof LongAdd || var1 instanceof Negation) {
            s1 = "(" + s1 + ")";
        }
        String s2 = var2.toString();
        if (var2 instanceof Add || var2 instanceof LongAdd || var2 instanceof Negation) {
            s2 = "(" + s2 + ")";
        }
        return s1 + "*" + s2;
    }

    @Override
    public String toStringWithSign() {
        return "+" + toString();
    }
}
